﻿namespace OboutInc.SlideMenu
{
    using OboutInc.SlideMenu.Designer;
    using System;
    using System.Collections.Specialized;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Drawing.Design;
    using System.Web.UI;
    using System.Xml;

    [ParseChildren(true), PersistChildren(false), Designer(typeof(SlideMenuDesigner), typeof(IDesigner))]
    public class SlideMenu : Control, INamingContainer, IPostBackDataHandler
    {
        private SlideMenuItems _items;
        private ScriptManagerHelper myScriptManager;
        private string versionNumber = "3.3.1.5";

        public void AddChild(string id, string innerHtml)
        {
            this.AddChild(id, innerHtml, null, null, null, null);
        }

        public void AddChild(string id, string innerHtml, string url)
        {
            this.AddChild(id, innerHtml, url, null, null, null);
        }

        public void AddChild(string id, string innerHtml, string url, string onClientClick)
        {
            this.AddChild(id, innerHtml, url, onClientClick, null, null);
        }

        public void AddChild(string id, string innerHtml, string url, string onClientClick, string urlTitle)
        {
            this.AddChild(id, innerHtml, url, onClientClick, urlTitle, null);
        }

        public void AddChild(string id, string innerHtml, string url, string onClientClick, string urlTitle, string urlTarget)
        {
            if ((id == null) || (id == string.Empty))
            {
                throw new Exception("obout SlideMenu AddChild: ID is not set.");
            }
            Child i = new Child {
                ID = id,
                InnerHtml = innerHtml,
                Url = url,
                OnClientClick = (onClientClick == null) ? string.Empty : onClientClick,
                UrlTitle = urlTitle,
                UrlTarget = urlTarget
            };
            this.MenuItems.Add(i);
        }

        public void AddChildAt(string id, string atId, string innerHtml, string url, string onClientClick, string urlTitle)
        {
            this.AddChildAt(id, atId, innerHtml, url, onClientClick, urlTitle, null);
        }

        public void AddChildAt(string id, string atId, string innerHtml, string url, string onClientClick, string urlTitle, string urlTarget)
        {
            if ((id == null) || (id == string.Empty))
            {
                throw new Exception("obout SlideMenu AddChild: ID is not set.");
            }
            Child item = new Child {
                ID = id,
                InnerHtml = innerHtml,
                Url = url,
                OnClientClick = (onClientClick == null) ? string.Empty : onClientClick,
                UrlTitle = urlTitle,
                UrlTarget = urlTarget
            };
            this.MenuItems.InsertItemAt(atId, item);
        }

        public void AddParent(string id, string innerHtml)
        {
            this.AddParent(id, innerHtml, null, null, null, null);
        }

        public void AddParent(string id, string innerHtml, string url)
        {
            this.AddParent(id, innerHtml, url, null, null, null);
        }

        public void AddParent(string id, string innerHtml, string url, string onClientClick)
        {
            this.AddParent(id, innerHtml, url, onClientClick, null, null);
        }

        public void AddParent(string id, string innerHtml, string url, string onClientClick, string urlTitle)
        {
            this.AddParent(id, innerHtml, url, onClientClick, urlTitle, null);
        }

        public void AddParent(string id, string innerHtml, string url, string onClientClick, string urlTitle, string urlTarget)
        {
            if ((id == null) || (id == string.Empty))
            {
                throw new Exception("obout SlideMenu AddParent: ID is not set.");
            }
            Parent i = new Parent {
                ID = id,
                InnerHtml = innerHtml,
                Url = url,
                OnClientClick = (onClientClick == null) ? string.Empty : onClientClick,
                UrlTitle = urlTitle,
                UrlTarget = urlTarget
            };
            this.MenuItems.Add(i);
        }

        public void AddParentAt(string id, string atId, string innerHtml, string url, string onClientClick, string urlTitle)
        {
            this.AddParentAt(id, atId, innerHtml, url, onClientClick, urlTitle, null);
        }

        public void AddParentAt(string id, string atId, string innerHtml, string url, string onClientClick, string urlTitle, string urlTarget)
        {
            if ((id == null) || (id == string.Empty))
            {
                throw new Exception("obout Slide Menu AddParentAt: ID is not set.");
            }
            Parent item = new Parent {
                ID = id,
                InnerHtml = innerHtml,
                Url = url,
                OnClientClick = (onClientClick == null) ? string.Empty : onClientClick,
                UrlTitle = urlTitle,
                UrlTarget = urlTarget
            };
            this.MenuItems.InsertItemAt(atId, item);
        }

        private bool CheckAjaxPageInheritance()
        {
            Type baseType = this.Page.GetType().BaseType;
            while (baseType != null)
            {
                if (baseType.ToString() == "OboutInc.oboutAJAXPage")
                {
                    return true;
                }
                try
                {
                    baseType = Activator.CreateInstance(baseType).GetType().BaseType;
                    continue;
                }
                catch
                {
                    return false;
                }
            }
            return false;
        }

        public void Clear()
        {
            this.ViewState["MenuItems"] = null;
            this._items.Clear();
        }

        protected override void CreateChildControls()
        {
            if ((this.XmlPath != string.Empty) && (this.ViewState["MenuItems"] == null))
            {
                this.LoadXml();
            }
            foreach (SlideMenuItem item in this.MenuItems)
            {
                this.Controls.Add(item);
            }
            base.CreateChildControls();
        }

        private void deserializeCollection()
        {
            if ((this.ViewState["MenuItems"] != null) && (this._items == null))
            {
                XmlDocument document = new XmlDocument();
                document.LoadXml((string) this.ViewState["MenuItems"]);
                if (document.DocumentElement.HasChildNodes)
                {
                    XmlNodeList childNodes = document.DocumentElement.ChildNodes;
                    for (int i = 0; i < childNodes.Count; i++)
                    {
                        SlideMenuItem item;
                        if (childNodes[i].Name == "parent")
                        {
                            item = new Parent();
                        }
                        else
                        {
                            item = new Child();
                        }
                        item.ID = childNodes[i].Attributes.GetNamedItem("id").Value;
                        item.Url = childNodes[i].Attributes.GetNamedItem("url").Value;
                        item.UrlTarget = childNodes[i].Attributes.GetNamedItem("urltarget").Value;
                        item.OnClientClick = childNodes[i].Attributes.GetNamedItem("onclientclick").Value;
                        item.UrlTitle = childNodes[i].Attributes.GetNamedItem("urltitle").Value;
                        item.InnerHtml = childNodes[i].InnerText;
                        this.MenuItems.Add(item);
                    }
                }
            }
        }

        private string getMenuId()
        {
            if ((this.ID != null) && !(this.ID == string.Empty))
            {
                return this.ID;
            }
            return this.ClientID;
        }

        public bool LoadPostData(string postDataKey, NameValueCollection postCollection)
        {
            string str = postCollection["h_" + this.getMenuId()];
            string text1 = postCollection["h_" + this.getMenuId() + "scroll"];
            switch (str)
            {
                case "":
                    return false;

                case "-1":
                    this.SelectedId = string.Empty;
                    return true;
            }
            this.SelectedId = str;
            return true;
        }

        protected override void LoadViewState(object savedState)
        {
            base.LoadViewState(savedState);
            this.deserializeCollection();
        }

        private void LoadXml()
        {
            bool flag = false;
            XmlTextReader reader = null;
            try
            {
                reader = new XmlTextReader(this.Page.MapPath(this.XmlPath)) {
                    WhitespaceHandling = WhitespaceHandling.None
                };
                while (reader.Read() && ((reader.NodeType != XmlNodeType.Element) || !(reader.Name.ToLower() == "slidemenu")))
                {
                }
                if (!reader.EOF)
                {
                    goto Label_0467;
                }
                reader.Close();
                throw new Exception("obout SlideMenu XML error: Could not find <SlideMenu> node");
            Label_0066:
                switch (reader.Name.ToLower())
                {
                    case "id":
                        this.ID = reader.Value;
                        break;

                    case "selectedid":
                        this.SelectedId = reader.Value;
                        break;

                    case "speed":
                        this.Speed = XmlConvert.ToInt32(reader.Value);
                        break;

                    case "keepexpanded":
                        this.KeepExpanded = XmlConvert.ToBoolean(reader.Value);
                        break;

                    case "cssparent":
                        this.CSSParent = reader.Value;
                        break;

                    case "cssparentover":
                        this.CSSParentOver = reader.Value;
                        break;

                    case "cssparentselected":
                        this.CSSParentSelected = reader.Value;
                        break;

                    case "csschild":
                        this.CSSChild = reader.Value;
                        break;

                    case "csschildover":
                        this.CSSChildOver = reader.Value;
                        break;

                    case "csschildselected":
                        this.CSSChildSelected = reader.Value;
                        break;

                    case "cssmenu":
                        this.CSSMenu = reader.Value;
                        break;

                    case "csschildrenbox":
                        this.CSSChildrenBox = reader.Value;
                        break;

                    case "imageparent":
                        this.ImageParent = reader.Value;
                        break;

                    case "imageparentover":
                        this.ImageParentOver = reader.Value;
                        break;

                    case "imageparentselected":
                        this.ImageParentSelected = reader.Value;
                        break;

                    case "imagechild":
                        this.ImageChild = reader.Value;
                        break;

                    case "imagechildover":
                        this.ImageChildOver = reader.Value;
                        break;

                    case "imagechildselected":
                        this.ImageChildSelected = reader.Value;
                        break;

                    case "cssimageparent":
                        this.CSSImageParent = reader.Value;
                        break;

                    case "cssimagechild":
                        this.CSSImageChild = reader.Value;
                        break;

                    case "minimumchildrenheight":
                        this.MinimumChildrenHeight = int.Parse(reader.Value);
                        break;

                    case "height":
                        this.Height = int.Parse(reader.Value);
                        break;

                    case "urltarget":
                        this.UrlTarget = reader.Value;
                        break;

                    case "csspath":
                        this.CSSPath = reader.Value;
                        break;

                    case "autoquerystring":
                        this.AutoQueryString = XmlConvert.ToBoolean(reader.Value);
                        break;

                    case "stylefolder":
                        this.StyleFolder = reader.Value;
                        break;

                    case "imagelongdescription":
                        this.ImageLongDescription = reader.Value;
                        break;

                    case "allexpanded":
                        this.AllExpanded = XmlConvert.ToBoolean(reader.Value);
                        break;
                }
            Label_0467:
                if (reader.MoveToNextAttribute())
                {
                    goto Label_0066;
                }
                while (reader.Read() && (reader.NodeType != XmlNodeType.Element))
                {
                }
                if (reader.EOF)
                {
                    reader.Close();
                }
                else
                {
                    for (string str = reader.Name.ToLower(); (str == "parent") || (str == "child"); str = reader.Name.ToLower())
                    {
                        SlideMenuItem item;
                        if (str == "parent")
                        {
                            item = new Parent();
                        }
                        else
                        {
                            item = new Child();
                        }
                        while (reader.MoveToNextAttribute())
                        {
                            string str3 = reader.Name.ToLower();
                            if (str3 != null)
                            {
                                if (!(str3 == "url"))
                                {
                                    if (str3 == "id")
                                    {
                                        goto Label_0541;
                                    }
                                    if (str3 == "innerhtml")
                                    {
                                        goto Label_054F;
                                    }
                                    if (str3 == "onclientclick")
                                    {
                                        goto Label_055F;
                                    }
                                    if (str3 == "urltarget")
                                    {
                                        goto Label_056D;
                                    }
                                    if (str3 == "urltitle")
                                    {
                                        goto Label_057B;
                                    }
                                }
                                else
                                {
                                    item.Url = reader.Value;
                                }
                            }
                            continue;
                        Label_0541:
                            item.ID = reader.Value;
                            continue;
                        Label_054F:
                            item.InnerHtml = reader.Value;
                            flag = true;
                            continue;
                        Label_055F:
                            item.OnClientClick = reader.Value;
                            continue;
                        Label_056D:
                            item.UrlTarget = reader.Value;
                            continue;
                        Label_057B:
                            item.UrlTitle = reader.Value;
                        }
                        reader.MoveToElement();
                        if (!flag)
                        {
                            item.InnerHtml = reader.ReadInnerXml();
                        }
                        else
                        {
                            reader.Read();
                        }
                        flag = false;
                        this.MenuItems.Add(item);
                        if (reader.NodeType != XmlNodeType.Element)
                        {
                            while (reader.Read() && (reader.NodeType != XmlNodeType.Element))
                            {
                            }
                        }
                    }
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }

        protected override void OnInit(EventArgs e)
        {
            if (this._items != null)
            {
                this.EnsureChildControls();
            }
            base.OnInit(e);
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            this.Page.ClientScript.RegisterHiddenField("h_" + this.getMenuId(), "");
            this.Page.ClientScript.RegisterHiddenField("h_" + this.getMenuId() + "scroll", "");
            this.Page.RegisterRequiresPostBack(this);
        }

        public void RaisePostDataChangedEvent()
        {
        }

        protected override void Render(HtmlTextWriter output)
        {
            string str = "";
            bool flag = true;
            this.myScriptManager = new ScriptManagerHelper(this);
            try
            {
                this.Page.VerifyRenderingInServerForm(this);
            }
            catch
            {
                flag = false;
            }
            if (this.AllExpanded)
            {
                this.KeepExpanded = true;
            }
            string str2 = null;
            bool flag2 = false;
            bool flag3 = false;
            int num = 0;
            string str15 = "";
            string str16 = "";
            string str17 = "";
            string str18 = "";
            string str19 = "";
            string str20 = "";
            string str21 = "";
            string str22 = "";
            string str7 = "\"SMParent\"";
            string str8 = "\"SMParentOver\"";
            string str9 = "\"SMParentSelected\"";
            string str10 = "\"SMChild\"";
            string str11 = "\"SMChildOver\"";
            string str12 = "\"SMChildSelected\"";
            string str13 = "\"SMMenu\"";
            string str14 = "\"SMChildrenBox\"";
            str21 = "\"SMImageParent\"";
            str22 = "\"SMImageChild\"";
            if (this.StyleFolder != string.Empty)
            {
                str15 = "\"" + this.StyleFolder + "/parent.gif\"";
                str16 = "\"" + this.StyleFolder + "/parentover.gif\"";
                str17 = "\"" + this.StyleFolder + "/parentselected.gif\"";
                str18 = "\"" + this.StyleFolder + "/child.gif\"";
                str19 = "\"" + this.StyleFolder + "/childover.gif\"";
                str20 = "\"" + this.StyleFolder + "/childselected.gif\"";
                this.CSSPath = this.StyleFolder + "/style.css";
            }
            string selectedId = this.SelectedId;
            string str5 = (selectedId == string.Empty) ? "null" : ("\"" + selectedId + "\"");
            bool flag4 = false;
            if (this.CSSPath != string.Empty)
            {
                selectedId = (string) this.ViewState["CSSParent"];
                str7 = (selectedId == null) ? str7 : ("\"" + selectedId + "\"");
                selectedId = (string) this.ViewState["CSSParentOver"];
                str8 = (selectedId == null) ? str8 : ("\"" + selectedId + "\"");
                selectedId = (string) this.ViewState["CSSParentSelected"];
                str9 = (selectedId == null) ? str9 : ("\"" + selectedId + "\"");
                selectedId = (string) this.ViewState["CSSChild"];
                str10 = (selectedId == null) ? str10 : ("\"" + selectedId + "\"");
                selectedId = (string) this.ViewState["CSSChildOver"];
                str11 = (selectedId == null) ? str11 : ("\"" + selectedId + "\"");
                selectedId = (string) this.ViewState["CSSChildSelected"];
                str12 = (selectedId == null) ? str12 : ("\"" + selectedId + "\"");
                selectedId = (string) this.ViewState["CSSMenu"];
                str13 = (selectedId == null) ? str13 : ("\"" + selectedId + "\"");
                selectedId = (string) this.ViewState["CSSChildrenBox"];
                str14 = (selectedId == null) ? str14 : ("\"" + selectedId + "\"");
                selectedId = (string) this.ViewState["CSSImageParent"];
                str21 = (selectedId == null) ? str21 : ("\"" + selectedId + "\"");
                selectedId = (string) this.ViewState["CSSImageChild"];
                str22 = (selectedId == null) ? str22 : ("\"" + selectedId + "\"");
            }
            else if ((((this.ViewState["CSSParent"] != null) || (this.ViewState["CSSParentOver"] != null)) || ((this.ViewState["CSSParentSelected"] != null) || (this.ViewState["CSSChild"] != null))) || ((((this.ViewState["CSSChildOver"] != null) || (this.ViewState["CSSChildSelected"] != null)) || ((this.ViewState["CSSMenu"] != null) || (this.ViewState["CSSChildrenBox"] != null))) || ((this.ViewState["CSSImageParent"] != null) || (this.ViewState["CSSImageChild"] != null))))
            {
                selectedId = (string) this.ViewState["CSSParent"];
                str7 = (selectedId == null) ? "null" : ("\"" + selectedId + "\"");
                selectedId = (string) this.ViewState["CSSParentOver"];
                str8 = (selectedId == null) ? "null" : ("\"" + selectedId + "\"");
                selectedId = (string) this.ViewState["CSSParentSelected"];
                str9 = (selectedId == null) ? "null" : ("\"" + selectedId + "\"");
                selectedId = (string) this.ViewState["CSSChild"];
                str10 = (selectedId == null) ? "null" : ("\"" + selectedId + "\"");
                selectedId = (string) this.ViewState["CSSChildOver"];
                str11 = (selectedId == null) ? "null" : ("\"" + selectedId + "\"");
                selectedId = (string) this.ViewState["CSSChildSelected"];
                str12 = (selectedId == null) ? "null" : ("\"" + selectedId + "\"");
                selectedId = (string) this.ViewState["CSSMenu"];
                str13 = (selectedId == null) ? "null" : ("\"" + selectedId + "\"");
                selectedId = (string) this.ViewState["CSSChildrenBox"];
                str14 = (selectedId == null) ? "null" : ("\"" + selectedId + "\"");
                selectedId = (string) this.ViewState["CSSImageParent"];
                str21 = (selectedId == null) ? "null" : ("\"" + selectedId + "\"");
                selectedId = (string) this.ViewState["CSSImageChild"];
                str22 = (selectedId == null) ? "null" : ("\"" + selectedId + "\"");
            }
            else
            {
                flag4 = true;
            }
            selectedId = (string) this.ViewState["ImageParent"];
            str15 = (selectedId == null) ? ((str15 == string.Empty) ? "null" : str15) : ("\"" + selectedId + "\"");
            selectedId = (string) this.ViewState["ImageParentOver"];
            str16 = (selectedId == null) ? ((str16 == string.Empty) ? "null" : str16) : ("\"" + selectedId + "\"");
            selectedId = (string) this.ViewState["ImageParentSelected"];
            str17 = (selectedId == null) ? ((str17 == string.Empty) ? "null" : str17) : ("\"" + selectedId + "\"");
            selectedId = (string) this.ViewState["ImageChild"];
            str18 = (selectedId == null) ? ((str18 == string.Empty) ? "null" : str18) : ("\"" + selectedId + "\"");
            selectedId = (string) this.ViewState["ImageChildOver"];
            str19 = (selectedId == null) ? ((str19 == string.Empty) ? "null" : str19) : ("\"" + selectedId + "\"");
            selectedId = (string) this.ViewState["ImageChildSelected"];
            str20 = (selectedId == null) ? ((str20 == string.Empty) ? "null" : str20) : ("\"" + selectedId + "\"");
            int height = this.Height;
            int minimumChildrenHeight = this.MinimumChildrenHeight;
            object obj2 = this.ViewState["KeepExpanded"];
            string str6 = (obj2 == null) ? "false" : ((bool) obj2).ToString();
            str6 = ((str6 == "False") || (str6 == "false")) ? "false" : "true";
            string str3 = this.getMenuId();
            str = "";
            string relativeUrl = "";
            if (this.CSSPath != string.Empty)
            {
                relativeUrl = this.CSSPath.Replace(@"\", "/");
                relativeUrl = base.ResolveUrl(relativeUrl);
            }
            else if (flag4)
            {
                relativeUrl = this.Page.ClientScript.GetWebResourceUrl(base.GetType(), "OboutInc.SlideMenu.styles.basic.style.css");
            }
            if (relativeUrl != string.Empty)
            {
                str = str + "<link type =\"text/css\" href=\"" + relativeUrl + "\" rel=\"StyleSheet\" media=\"all\"/>";
            }
            output.Write(str);
            output.Write("<div id=\"" + str3 + "\" style=\"visibility:hidden;\">");
            foreach (SlideMenuItem item in this.MenuItems)
            {
                string argument = ((item.ID == null) || (item.ID == string.Empty)) ? item.ClientID : item.ID;
                if (item._itemType == 0)
                {
                    if (flag2)
                    {
                        output.Write("</div>");
                    }
                    output.Write("<div id=\"" + argument + "\"");
                    if ((item.OnClientClick != string.Empty) || (item._eventCount > 0))
                    {
                        output.Write(" onclick=\"");
                        if (item.OnClientClick != string.Empty)
                        {
                            output.Write(item.OnClientClick);
                        }
                        if (item._eventCount > 0)
                        {
                            output.Write(this.Page.ClientScript.GetPostBackEventReference(item, argument));
                        }
                        output.Write("\"");
                    }
                    output.Write(">");
                    if (item.Url != string.Empty)
                    {
                        string[] strArray = item.Url.Split(new char[] { '#' });
                        if (this.AutoQueryString)
                        {
                            if (item.Url.IndexOf('?') >= 0)
                            {
                                output.Write("<a href=\"" + strArray[0] + "&sm=" + argument + ((strArray.Length > 1) ? ("#" + strArray[1]) : "") + "\"");
                            }
                            else
                            {
                                output.Write("<a href=\"" + strArray[0] + "?sm=" + argument + ((strArray.Length > 1) ? ("#" + strArray[1]) : "") + "\"");
                            }
                        }
                        else
                        {
                            output.Write("<a href=\"" + item.Url + "\"");
                        }
                        if (item.UrlTarget != string.Empty)
                        {
                            output.Write(" target=\"" + item.UrlTarget + "\"");
                        }
                        else if (this.UrlTarget != string.Empty)
                        {
                            output.Write(" target=\"" + this.UrlTarget + "\"");
                        }
                        if (item.UrlTitle != string.Empty)
                        {
                            output.Write(" title=\"" + item.UrlTitle + "\"");
                        }
                        output.Write("><div>");
                    }
                    else
                    {
                        output.Write("<a title=\"" + item.UrlTitle + "\"></a>");
                    }
                    if (str15 != "null")
                    {
                        output.Write("<img id=\"__i" + argument + "\" " + ((this.ImageLongDescription == string.Empty) ? "" : ("longdesc=\"" + this.ImageLongDescription + "\" ")) + "/>");
                    }
                    item.RenderControl(output);
                    if (item.Url != string.Empty)
                    {
                        output.Write("</div></a>");
                    }
                    output.Write("</div>");
                    str2 = argument;
                    flag2 = false;
                }
                else
                {
                    if (str2 != null)
                    {
                        output.Write("<div id=\"__" + str2 + "\">");
                    }
                    output.Write("<div id=\"" + argument + "\"");
                    if ((this.AutoPostBack || (item.OnClientClick != string.Empty)) || (item._eventCount > 0))
                    {
                        output.Write(" onclick=\"");
                        if (item.OnClientClick != string.Empty)
                        {
                            output.Write(item.OnClientClick);
                        }
                        if (this.AutoPostBack || (item._eventCount > 0))
                        {
                            output.Write(this.Page.ClientScript.GetPostBackEventReference(item, argument));
                        }
                        output.Write("\"");
                    }
                    output.Write(">");
                    if (item.Url != string.Empty)
                    {
                        string[] strArray2 = item.Url.Split(new char[] { '#' });
                        if (this.AutoQueryString)
                        {
                            if (item.Url.IndexOf('?') >= 0)
                            {
                                output.Write("<a href=\"" + strArray2[0] + "&sm=" + argument + ((strArray2.Length > 1) ? ("#" + strArray2[1]) : "") + "\"");
                            }
                            else
                            {
                                output.Write("<a href=\"" + strArray2[0] + "?sm=" + argument + ((strArray2.Length > 1) ? ("#" + strArray2[1]) : "") + "\"");
                            }
                        }
                        else
                        {
                            output.Write("<a href=\"" + item.Url + "\"");
                        }
                        if (item.UrlTarget != string.Empty)
                        {
                            output.Write(" target=\"" + item.UrlTarget + "\"");
                        }
                        else if (this.UrlTarget != string.Empty)
                        {
                            output.Write(" target=\"" + this.UrlTarget + "\"");
                        }
                        if (item.UrlTitle != string.Empty)
                        {
                            output.Write(" title=\"" + item.UrlTitle + "\"");
                        }
                        output.Write("><div>");
                    }
                    if (str18 != "null")
                    {
                        output.Write("<img id=\"__i" + argument + "\" " + ((this.ImageLongDescription == string.Empty) ? "" : ("longdesc=\"" + this.ImageLongDescription + "\" ")) + "/>");
                    }
                    item.RenderControl(output);
                    if (item.Url != string.Empty)
                    {
                        output.Write("</div></a>");
                    }
                    output.Write("</div>");
                    str2 = null;
                    flag2 = true;
                }
                num++;
                if (flag3 && (num > 0x13))
                {
                    break;
                }
            }
            if (flag2)
            {
                output.Write("</div>");
            }
            output.Write("</div>");
            if (flag3)
            {
                output.Write("<div" + ((str13 == "null") ? "" : (" class=" + str13)) + "<div style=\"text-align:center; border: 2px solid #cccccc; height: 60 px; font: 8pt verdana; background-color: #eeeeee;\"><a href=\"http://www.obout.com\">obout slide menu</a><br />Evaluation has expired<br /><a href=\"http://www.obout.com/inc/purchase.aspx\">License ...</a></div></div>");
            }
            str = "";
            string webResourceUrl = this.Page.ClientScript.GetWebResourceUrl(base.GetType(), "OboutInc.SlideMenu.script.SlideMenu.js");
            str = str + "<script id=\"OboutSlideMenuScriptLibrary\" type=\"text/javascript\" src=\"" + webResourceUrl + "\"></script>";
            if ((!flag || this.CheckAjaxPageInheritance()) || this.myScriptManager.isAjax)
            {
                if (this.myScriptManager.isAjax && this.myScriptManager.IsInAsyncPostBack)
                {
                    this.myScriptManager.RegisterClientScriptBlock(this, "OboutSlideMenuScriptLibrary", "(function(){var head = document.getElementsByTagName('HEAD')[0];if (head) {if(document.getElementById(\"OboutSlideMenuScriptLibrary\") != null) return;var linkElement = document.createElement('script');linkElement.type = 'text/javascript';linkElement.src = '" + webResourceUrl + "';linkElement.id = 'OboutSlideMenuScriptLibrary';head.appendChild(linkElement);}})();", true);
                }
                else
                {
                    output.Write(str);
                }
            }
            else
            {
                this.myScriptManager.RegisterStartupScript(this, webResourceUrl, str, false);
            }
            str = "";
            if (!flag || this.CheckAjaxPageInheritance())
            {
                str = str + "<script type=\"text/javascript\">";
            }
            string str27 = ((((((((str + "function f_" + str3 + "() {") + "var i, j, o, oc, ob;") + "o = document.getElementById(\"" + str3 + "\");") + "for(i = 0; i < o.childNodes.length; i++) {") + "oc = o.childNodes[i];" + "if(oc.id.substring(0, 2) != \"__\") {") + "oc.onmouseover = function() {oboutSM" + str3 + ".mouseOverOutSelected(this.id, 1, true);};") + "oc.onmouseout = function() {oboutSM" + str3 + ".mouseOverOutSelected(this.id, 0, true);};") + "if(oc.onclick) {") + "oboutSM" + str3 + ".addFunction(oc.onclick, oc.id);";
            string str28 = str27 + "oc.onclick = function() {oboutSM" + str3 + ".parentClick(this.id); oboutSM" + str3 + ".getFunction(this.id)();};";
            string str29 = (((((((((str28 + "oc.firstChild.onclick = function() {oboutSM" + str3 + ".parentClick(this.parentElement.id); oboutSM" + str3 + ".getFunction(this.parentElement.id)();};") + "}" + "else {") + "oc.onclick = function() {oboutSM" + str3 + ".parentClick(this.id);};") + "oc.firstChild.onclick = function() {oboutSM" + str3 + ".parentClick(this.parentElement.id);};") + "}" + "} else ") + "for(j = 0; j < oc.childNodes.length; j++) {" + "ob = oc.childNodes[j];") + "ob.onmouseover = function() {oboutSM" + str3 + ".mouseOverOutSelected(this.id, 4, true);};") + "ob.onmouseout = function() {oboutSM" + str3 + ".mouseOverOutSelected(this.id, 3, true);};") + "if(ob.onclick) {") + "oboutSM" + str3 + ".addFunction(ob.onclick, ob.id);";
            str = ((((((str29 + "ob.onclick = function() {oboutSM" + str3 + ".saveHidden(this.id); oboutSM" + str3 + ".getFunction(this.id)();};") + "}" + "else ") + "ob.onclick = function() {oboutSM" + str3 + ".saveHidden(this.id);};") + "}" + "}") + "oboutSM" + str3 + ".buildMenu();") + "}") + "function start_" + str3 + "() {";
            if (this.myScriptManager.isAjax && this.myScriptManager.IsInAsyncPostBack)
            {
                str = str + "if(typeof SlideMenu == 'undefined') { setTimeout(function(){start_" + str3 + "();}, 10); return;}";
            }
            object obj3 = str;
            str = string.Concat(new object[] { 
                obj3, "try {window.oboutSM", str3, " = new SlideMenu(\"", str3, "\", ", str5, ", ", this.Speed, ", ", str6, ", ", str7, ", ", str8, ", ", 
                str9, ", ", str10, ", ", str11, ", ", str12, ", ", str13, ", ", str14, ", ", str15, ", ", str16, ", ", 
                str17, ", ", str18, ", ", str19, ", ", str20, ", ", str21, ", ", str22, ", ", height, ", ", minimumChildrenHeight, ", ", 
                (this.ViewState["scrollPosition"] == null) ? "null" : ((string) this.ViewState["scrollPosition"]), ", ", this.AllExpanded ? "true" : "false", ");"
             }) + "} catch(e) {" + "}";
            if (this.myScriptManager.isAjax || this.CheckAjaxPageInheritance())
            {
                str = str + "f_" + str3 + "();";
                if (height <= 0)
                {
                    str = ((((((((((str + "function fteo_" + str3 + "() {") + "var par = document.getElementById(\"" + str3 + "\");") + "while (par != null)" + "{") + "    if (par.style && oboutSM" + str3 + ".getStyle(par, 'display') == 'none')") + "    {") + "        setTimeout(fteo_" + str3 + ",10); return;") + "    }") + "    par = par.parentNode;" + "}") + "oboutSM" + str3 + ".collapseAll();") + "}") + "fteo_" + str3 + "();";
                }
            }
            else
            {
                string str30 = str;
                str = str30 + "oboutSM" + str3 + ".SafeAddOnload(f_" + str3 + ", oboutSM" + str3 + ");";
                if (height <= 0)
                {
                    string str31 = str;
                    str = str31 + "oboutSM" + str3 + ".SafeAddOnload(function() {oboutSM" + str3 + ".collapseAll()}, oboutSM" + str3 + ");";
                }
            }
            str = (str + "}") + "start_" + str3 + "();";
            string userAgent = "";
            if (this.Page.Request.UserAgent != null)
            {
                userAgent = this.Page.Request.UserAgent;
            }
            if ((userAgent.IndexOf("MSIE") != -1) && this.myScriptManager.isAjax)
            {
                string str32 = (str + "if (document.getElementById('" + this.ID + "_css')!=null)") + "{";
                str = ((((((str32 + "document.getElementById('" + this.ID + "_css').href='" + relativeUrl + "';") + "}" + "else") + "{" + " var lt = document.createElement('link');") + "lt.href = '" + relativeUrl + "';") + "lt.type = 'text/css';") + "lt.media = 'all';" + "lt.rel = 'StyleSheet';") + "document.body.insertBefore(lt, document.body.firstChild);" + "}";
            }
            if (!flag || this.CheckAjaxPageInheritance())
            {
                str = str + "</script>";
            }
            if (!flag || this.CheckAjaxPageInheritance())
            {
                output.Write(str);
            }
            else
            {
                this.myScriptManager.RegisterStartupScript(this, this.ClientID, str, true);
            }
            output.Write("\n\n<!--   obout inc SlideMenu version " + this.versionNumber + "  http://www.obout.com   -->\n\n");
        }

        protected override object SaveViewState()
        {
            this.serializeCollection();
            return base.SaveViewState();
        }

        private void serializeCollection()
        {
            XmlDocument document = new XmlDocument();
            XmlNode newChild = document.CreateNode(XmlNodeType.Element, "slidemenu", "");
            foreach (SlideMenuItem item in this.MenuItems)
            {
                XmlElement element;
                if (item._itemType == 0)
                {
                    element = document.CreateElement("parent");
                }
                else
                {
                    element = document.CreateElement("child");
                }
                element.SetAttribute("id", item.ID);
                element.SetAttribute("url", item.Url);
                element.SetAttribute("urltarget", item.UrlTarget);
                element.SetAttribute("onclientclick", item.OnClientClick);
                element.SetAttribute("urltitle", item.UrlTitle);
                element.InnerText = item.InnerHtml;
                newChild.AppendChild(element);
            }
            document.AppendChild(newChild);
            this.ViewState["MenuItems"] = document.OuterXml;
        }

        [Category("Menu settings"), Bindable(true), Description("When true, menu renders with all items expanded.")]
        public bool AllExpanded
        {
            get
            {
                return ((this.ViewState["AllExpanded"] != null) && ((bool) this.ViewState["AllExpanded"]));
            }
            set
            {
                this.ViewState["AllExpanded"] = value;
            }
        }

        [Category("Menu settings"), Description("Automatically post back when child is selected."), Bindable(true)]
        public bool AutoPostBack
        {
            get
            {
                return ((this.ViewState["AutoPostBack"] != null) && ((bool) this.ViewState["AutoPostBack"]));
            }
            set
            {
                this.ViewState["AutoPostBack"] = value;
            }
        }

        [Bindable(true), Category("Menu settings"), Description("Automatically assign query string with ID to every URL.")]
        public bool AutoQueryString
        {
            get
            {
                return ((this.ViewState["AutoQueryString"] != null) && ((bool) this.ViewState["AutoQueryString"]));
            }
            set
            {
                this.ViewState["AutoQueryString"] = value;
            }
        }

        [Bindable(true), Description("CSS class name for child"), Category("Styles - Child"), DefaultValue("")]
        public string CSSChild
        {
            get
            {
                string str = (string) this.ViewState["CSSChild"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["CSSChild"] = value;
            }
        }

        [Bindable(true), DefaultValue("CSS class name for child with mouse over."), Category("Styles - Child")]
        public string CSSChildOver
        {
            get
            {
                string str = (string) this.ViewState["CSSChildOver"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["CSSChildOver"] = value;
            }
        }

        [Bindable(true), Category("Styles - Other"), DefaultValue("CSS class name for children box.")]
        public string CSSChildrenBox
        {
            get
            {
                string str = (string) this.ViewState["CSSChildrenBox"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["CSSChildrenBox"] = value;
            }
        }

        [DefaultValue("CSS class name for selected child"), Bindable(true), Category("Styles - Child")]
        public string CSSChildSelected
        {
            get
            {
                string str = (string) this.ViewState["CSSChildSelected"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["CSSChildSelected"] = value;
            }
        }

        [Bindable(true), Description("CSS class name for child image."), Category("Styles - Other"), DefaultValue("")]
        public string CSSImageChild
        {
            get
            {
                string str = (string) this.ViewState["CSSImageChild"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["CSSImageChild"] = value;
            }
        }

        [Category("Styles - Other"), Bindable(true), Description("CSS class name for parent image."), DefaultValue("")]
        public string CSSImageParent
        {
            get
            {
                string str = (string) this.ViewState["CSSImageParent"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["CSSImageParent"] = value;
            }
        }

        [Bindable(true), Description("CSS class name for menu."), DefaultValue(""), Category("Styles - Other")]
        public string CSSMenu
        {
            get
            {
                string str = (string) this.ViewState["CSSMenu"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["CSSMenu"] = value;
            }
        }

        [Category("Styles - Parent"), DefaultValue(""), Description("CSS class name for parent."), Bindable(true)]
        public string CSSParent
        {
            get
            {
                string str = (string) this.ViewState["CSSParent"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["CSSParent"] = value;
            }
        }

        [Description("CSS class name for parent with mouse over."), Bindable(true), DefaultValue(""), Category("Styles - Parent")]
        public string CSSParentOver
        {
            get
            {
                string str = (string) this.ViewState["CSSParentOver"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["CSSParentOver"] = value;
            }
        }

        [Description("CSS class name for selected parent."), Bindable(true), Category("Styles - Parent"), DefaultValue("")]
        public string CSSParentSelected
        {
            get
            {
                string str = (string) this.ViewState["CSSParentSelected"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["CSSParentSelected"] = value;
            }
        }

        [DefaultValue(""), Bindable(true), Description("Path to CSS file with menu classes."), Category("Styles - Other")]
        public string CSSPath
        {
            get
            {
                string str = (string) this.ViewState["CSSPath"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["CSSPath"] = value;
            }
        }

        [DefaultValue(""), Description("Height for every children box."), Category("Menu settings"), Bindable(true)]
        public int Height
        {
            get
            {
                if (this.ViewState["Height"] != null)
                {
                    return (int) this.ViewState["Height"];
                }
                return 100;
            }
            set
            {
                this.ViewState["Height"] = value;
            }
        }

        [Category("Image - Child"), Bindable(true), Description("Path to an image file for child."), DefaultValue("")]
        public string ImageChild
        {
            get
            {
                string str = (string) this.ViewState["ImageChild"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["ImageChild"] = value;
            }
        }

        [Description("Path to an image file for child with mouse over."), Bindable(true), Category("Image - Child"), DefaultValue("")]
        public string ImageChildOver
        {
            get
            {
                string str = (string) this.ViewState["ImageChildOver"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["ImageChildOver"] = value;
            }
        }

        [Description("Path to an image file for selected child."), Bindable(true), Category("Image - Child"), DefaultValue("")]
        public string ImageChildSelected
        {
            get
            {
                string str = (string) this.ViewState["ImageChildSelected"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["ImageChildSelected"] = value;
            }
        }

        [Bindable(true), DefaultValue(""), Description("Long description for all menu images."), Category("Menu settings")]
        public string ImageLongDescription
        {
            get
            {
                string str = (string) this.ViewState["ImageLongDescription"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["ImageLongDescription"] = value;
            }
        }

        [Bindable(true), Category("Image - Parent"), DefaultValue(""), Description("Path to an image file for parent.")]
        public string ImageParent
        {
            get
            {
                string str = (string) this.ViewState["ImageParent"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["ImageParent"] = value;
            }
        }

        [DefaultValue(""), Description("Path to an image file for parent with mouse over."), Bindable(true), Category("Image - Parent")]
        public string ImageParentOver
        {
            get
            {
                string str = (string) this.ViewState["ImageParentOver"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["ImageParentOver"] = value;
            }
        }

        [Category("Image - Parent"), Bindable(true), Description("Path to an image file for selected parent."), DefaultValue("")]
        public string ImageParentSelected
        {
            get
            {
                string str = (string) this.ViewState["ImageParentSelected"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["ImageParentSelected"] = value;
            }
        }

        [Category("Behavior"), Bindable(true), Description("Specify to leave opened parent expanded when another parent is selected."), DefaultValue("")]
        public bool KeepExpanded
        {
            get
            {
                return ((this.ViewState["KeepExpanded"] != null) && ((bool) this.ViewState["KeepExpanded"]));
            }
            set
            {
                this.ViewState["KeepExpanded"] = value;
            }
        }

        [Category("Behavior"), Description("SlideMenu Parents and Children collection."), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), NotifyParentProperty(true), PersistenceMode(PersistenceMode.InnerProperty), Editor(typeof(SlideMenuItemsEditor), typeof(UITypeEditor))]
        public SlideMenuItems MenuItems
        {
            get
            {
                if (this._items == null)
                {
                    this._items = new SlideMenuItems();
                }
                return this._items;
            }
        }

        [DefaultValue(""), Description("Minimum height for every children box."), Category("Menu settings"), Bindable(true)]
        public int MinimumChildrenHeight
        {
            get
            {
                if (this.ViewState["MinimumChildrenHeight"] != null)
                {
                    return (int) this.ViewState["MinimumChildrenHeight"];
                }
                return 0;
            }
            set
            {
                this.ViewState["MinimumChildrenHeight"] = value;
            }
        }

        [Description("Parent or child ID, which to select on load."), Bindable(true), Category("Menu settings"), DefaultValue("")]
        public string SelectedId
        {
            get
            {
                string str = (string) this.ViewState["SelectedId"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["SelectedId"] = value;
            }
        }

        [Description("Expand/collapse speed."), Bindable(true), Category("Behavior"), DefaultValue("")]
        public int Speed
        {
            get
            {
                object obj2 = this.ViewState["Speed"];
                if (obj2 != null)
                {
                    return (int) obj2;
                }
                return 10;
            }
            set
            {
                if (value < 0)
                {
                    this.ViewState["speed"] = 10;
                }
                else
                {
                    this.ViewState["Speed"] = value;
                }
            }
        }

        [Category("Styles - Other"), DefaultValue(""), Description("Path to folder with menu style."), Bindable(true)]
        public string StyleFolder
        {
            get
            {
                string str = (string) this.ViewState["StyleFolder"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["StyleFolder"] = value;
            }
        }

        [Description("Name of target frame for URLs."), Bindable(true), Category("Menu settings"), DefaultValue("")]
        public string UrlTarget
        {
            get
            {
                string str = (string) this.ViewState["UrlTarget"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["UrlTarget"] = value;
            }
        }

        [Bindable(true), Category("Menu settings"), Description("Path to XML file."), DefaultValue("")]
        public string XmlPath
        {
            get
            {
                string str = (string) this.ViewState["XmlPath"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["XmlPath"] = value;
            }
        }
    }
}

